package com.rf.service;


import com.rf.bean.Student;
import com.rf.mapper.StudentMapper;
import com.rf.page.PageBean;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description TODO
 * @Author hxj
 * @Date 2022/3/24 9:40 星期四
 */
@Component
public class StudentService {

    @Resource
    StudentMapper mapper;

    public boolean add(Student student){
        if (student == null){
            return false;
        }
        return mapper.add(student)>=1;
    }

    public boolean update(Student student){
        if (student==null){
            return false;
        }
        return mapper.update(student)>=1;
    }

    @Transactional
    public boolean delete(int id){
        if (id<1){
            return false;
        }
        return mapper.delete(id)>=1;
    }

    public Student getById(int id){
        return mapper.getById(id);
    }

    public List<Student> getAll(){
        List<Student> studentList = null;
        return mapper.getAll();
    }

    public void getByPage(PageBean<Student> pageBean){
        int rows = mapper.getTotalRows();
        pageBean.setTotalRows(rows);
        List<Student> stuList = mapper.getByPage(pageBean);
        pageBean.setData(stuList);
    }

}

